 #include "messagepops.h"
#include "ui_messagepops.h"
#include <QGraphicsDropShadowEffect>
#include <QtMath>
#include <QDebug>

MessagePops::MessagePops(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::MessagePops)
{
    ui->setupUi(this);

    //弹出子窗口时禁用主窗口
    this->setWindowModality(Qt::ApplicationModal); //阻塞除当前窗体之外的所有的窗体

    this->setAttribute(Qt::WA_TranslucentBackground);//设置窗口背景透明
    this->setWindowFlags(Qt::FramelessWindowHint);   //设置无边框窗口
//    this->setWindowFlags(Qt::Popup);//参数Qt::Popup 表示：当点击窗口以外即关闭窗口

    //设置具体阴影
    QGraphicsDropShadowEffect *shadow_effect = new QGraphicsDropShadowEffect(this);
    shadow_effect->setOffset(0, 0);

    //阴影颜色
    shadow_effect->setColor(QColor(38, 78, 119, 127));
    //阴影半径
    shadow_effect->setBlurRadius(10);
    ui->label->setGraphicsEffect(shadow_effect);
}

MessagePops::~MessagePops()
{
    delete ui;
}

//设置提示语
void MessagePops::setText(QString str)
{
    ui->pushButton_2->hide();
    ui->pushButton_3->hide();
    ui->pushButton->show();
    ui->pushButton_4->show();

    QStringList mylist=QString(str).split("@#");
    if(mylist.size()==1)
    {
//        ui->label_3->setGeometry(35,85,200,60);
//        ui->label_3->setWordWrap(true);//自动换行
//        QString strHeightText = "<p style=\"line-height:%1%\">%2<p>";
//        str = strHeightText.arg(100).arg(str);//设置行高

        ui->label_3->setText(str);
        ui->label_4->setText("");
        ui->label_5->setText("");
    }
    if(mylist.size()==2)
    {
        ui->label_3->setText(mylist.at(0));
        ui->label_4->setText(mylist.at(1));
        ui->label_5->setText("");
    }
    else if(mylist.size()==3)
    {
        ui->label_3->setText(mylist.at(0));
        ui->label_4->setText(mylist.at(1));
        ui->label_5->setText(mylist.at(2));
    }
}

//设置多个按钮提示语
void MessagePops::setTexts(QString str)
{
    ui->pushButton->hide();
    ui->pushButton_2->show();
    ui->pushButton_3->show();
    ui->pushButton_4->show();

    QStringList mylist=QString(str).split("@#");
//    qDebug()<<__LINE__<<"mylist.size="<<mylist.size();
    if(mylist.size()==1)
    {
        ui->label_3->setText(str);
        ui->label_4->setText("");
        ui->label_5->setText("");
    }
    else if(mylist.size()==2)
    {
        ui->label_3->setText(mylist.at(0));
        ui->label_4->setText(mylist.at(1));
        ui->label_5->setText("");
    }
    else if(mylist.size()==3)
    {
        ui->label_3->setText(mylist.at(0));
        ui->label_4->setText(mylist.at(1));
        ui->label_5->setText(mylist.at(2));
    }
}

//设置没有按钮不能关闭提示语
void MessagePops::setText0(QString str)
{
    ui->pushButton->hide();
    ui->pushButton_2->hide();
    ui->pushButton_3->hide();
    ui->pushButton_4->hide();

    QStringList mylist=QString(str).split("@#");
    if(mylist.size()==1)
    {
        ui->label_3->setText("");
        ui->label_4->setText(str);
        ui->label_5->setText("");
    }
    else if(mylist.size()==2)
    {
        ui->label_3->setText(mylist.at(0));
        ui->label_4->setText(mylist.at(1));
        ui->label_5->setText("");
    }
    else if(mylist.size()==3)
    {
        ui->label_3->setText(mylist.at(0));
        ui->label_4->setText(mylist.at(1));
        ui->label_5->setText(mylist.at(2));
    }
}

//设置按钮提示语
void MessagePops::setPushButton(QString str)
{
    QStringList mylist=QString(str).split("@#");

    if(mylist.size()==1)
    {
        ui->pushButton->setText(mylist.at(0));
    }
    else if(mylist.size()==2)
    {
        ui->pushButton_2->setText(mylist.at(0));
        ui->pushButton_3->setText(mylist.at(1));
    }
}

//点击了关闭按钮
void MessagePops::on_pushButton_4_clicked()
{
    this->close();
}

//点击确定按钮
void MessagePops::on_pushButton_clicked()
{
    emit sendMessage("1");
    this->close();
}

//点击否按钮
void MessagePops::on_pushButton_2_clicked()
{
    emit sendMessage("2");
    this->close();
}

//点击是按钮
void MessagePops::on_pushButton_3_clicked()
{
    emit sendMessage("3");
    this->close();
}
